package fun.anin.aninhongbao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import fun.anin.aninhongbao.entity.User;
import fun.anin.aninhongbao.dao.UserDao;
import fun.anin.aninhongbao.entity.Wallet;
import fun.anin.aninhongbao.result.R;
import fun.anin.aninhongbao.service.UserService;
import fun.anin.aninhongbao.service.WalletService;
import fun.anin.aninhongbao.util.IPUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2020-03-29 14:38:46
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired(required = false)
    private UserDao userDao;
    @Autowired
    private WalletService walletService;

    public R insert(HttpServletRequest request, User entity) {
        entity.setIp(IPUtils.getIpAddress(request));
        userDao.insert(entity);
        //初始化钱包
        Wallet wallet = Wallet.builder()
                .id(entity.getId())
                .build();
        walletService.save(wallet);
        return R.ok();
    }
}